package com.gw.validator;

import com.gw.base.BaseValidator;
import com.gw.common.model.Admin;
import com.gw.service.AdminService;
import com.jfinal.aop.Enhancer;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;


public class AdminLoginValidator extends BaseValidator{
	AdminService adminService=Enhancer.enhance(AdminService.class);
	@Override
	protected void validate(Controller c) {
		String name=c.getPara("userName");
		String pwd=c.getPara("pwd");
		if(StrKit.notBlank(name)&& StrKit.notBlank(pwd)){
			Admin admin=adminService.checkLogin(name);
			String loginName="";
			String loginPwd="";
			c.setAttr("admin", admin);
			
			if(StrKit.notNull(admin)){
				 loginName=admin.getStr("name");
				loginPwd=admin.getStr("password");
				validateEqualString(pwd, loginPwd, "passMsg", "密码错误");
			}else{
				validateEqualString(name, loginName, "nameMsg", "用户名错误");
			}
		}else{
			validateRequired("userName", "nameMsg", "用户名不能为空");
			validateRequired("pwd", "passMsg", "密码不能为空");
		}
	}

	@Override
	protected void handleError(Controller c) {
		
	}

}
